package com.anpy.anlibrary.utils

import com.tencent.mmkv.MMKV

object MMKVUtils {
    private var mmkv: MMKV = MMKV.defaultMMKV()

    fun getMmkv(): MMKV {
        return mmkv
    }

    fun saveString(key: String, value: String) {
        mmkv.encode(key, value)
    }

    fun getString(key: String): String? {
        return mmkv.decodeString(key)
    }

    fun getString(key: String, default: String): String? {
        return mmkv.decodeString(key, default)
    }

    fun saveBoolean(key: String, value: Boolean) {
        mmkv.encode(key, value)
    }

    fun getBoolean(key: String): Boolean {
        return mmkv.decodeBool(key)
    }

    fun getBoolean(key: String, defaultValue: Boolean): Boolean {
        return mmkv.decodeBool(key, defaultValue)
    }

    fun saveInt(key: String, value: Int) {
        mmkv.encode(key, value)
    }

    fun getInt(key: String, defaultValue: Int = 0): Int {
        return mmkv.decodeInt(key, defaultValue)
    }

    fun remove(key: String) {
        mmkv.removeValueForKey(key)
    }

    fun containKey(key: String): Boolean {
        return mmkv.containsKey(key)
    }

}